package com.huitone.gddw.service.dto;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.huitone.gddw.common.excel.ColToProperty;
import com.huitone.gddw.common.excel.TabCol;
import com.huitone.gddw.dao.entity.PrgExtInfo;
import com.huitone.gddw.dao.entity.PrgInfo;
import com.huitone.gddw.dao.entity.PrgRunningStatus.RunningStatus;

/**
 * 程序模块信息 DTO 对象
 * @author wuluodan
 *
 */
public class PrgInfoDTO {

	@ColToProperty
	@TabCol(Index = 1, title = "序号", width = "")
	private Integer seq;
	
	@ColToProperty
	@TabCol(Index = 2, title = "程序id", width = "")
	private String prgId;

	@ColToProperty
	@TabCol(Index = 3, title = "程序名称", width = "135")
    private String prgName;

	@ColToProperty
	@TabCol(Index = 4, title = "主程序名", width = "")
    private String groupName;

    @ColToProperty
	@TabCol(Index = 8, title = "部署主机(ip)", width = "75")
    private String deployId;

    private String deployDir;

    private String confDir;

    private String logDir;

    private String logBakDir;

    @ColToProperty
	@TabCol(Index = 9, title = "程序说明", width = "150")
    private String desc;

    private String status;

    private Date insertTime;

    private String insertStaffId;

    private Date lastModTime;

    private String lastModStaffId;
    
    private List<PrgExtInfo> prgExtInfos = new ArrayList<PrgExtInfo>();
    
    private String runningStatus;
    
    @ColToProperty
	@TabCol(Index = 6, title = "状态", width = "")
    private String runningStatusStr;
    
    @ColToProperty
	@TabCol(Index = 5, title = "模块名", width = "")
    private String moduleName;
    
    private Long runHours;
    
    @ColToProperty
	@TabCol(Index = 7, title = "运行时长", width = "")
    private String runTime;

	public PrgInfoDTO() {}
    
    public PrgInfoDTO(PrgInfo prgInfo) {
    	this.setPrgId(prgInfo.getPrgId());
    	this.setPrgName(prgInfo.getPrgName());
    	this.setGroupName(prgInfo.getGroupName());
    	this.setDeployId(prgInfo.getDeployId());
    	this.setDeployDir(prgInfo.getDeployDir());
    	this.setConfDir(prgInfo.getConfDir());
    	this.setLogDir(prgInfo.getLogDir());
    	this.setLogBakDir(prgInfo.getLogBakDir());
    	this.setDesc(prgInfo.getDesc());
    	this.setStatus(prgInfo.getStatus());
    	this.setInsertTime(prgInfo.getInsertTime());
    	this.setInsertStaffId(prgInfo.getInsertStaffId());
    	this.setLastModTime(prgInfo.getLastModTime());
    	this.setLastModStaffId(prgInfo.getLastModStaffId());
    }
    
    public PrgInfoDTO(PrgInfo prgInfo, List<PrgExtInfo> prgExtInfos) {
    	this.setPrgId(prgInfo.getPrgId());
    	this.setPrgName(prgInfo.getPrgName());
    	this.setGroupName(prgInfo.getGroupName());
    	this.setDeployId(prgInfo.getDeployId());
    	this.setDeployDir(prgInfo.getDeployDir());
    	this.setConfDir(prgInfo.getConfDir());
    	this.setLogDir(prgInfo.getLogDir());
    	this.setLogBakDir(prgInfo.getLogBakDir());
    	this.setDesc(prgInfo.getDesc());
    	this.setStatus(prgInfo.getStatus());
    	this.setInsertTime(prgInfo.getInsertTime());
    	this.setInsertStaffId(prgInfo.getInsertStaffId());
    	this.setLastModTime(prgInfo.getLastModTime());
    	this.setLastModStaffId(prgInfo.getLastModStaffId());
    	this.setPrgExtInfos(prgExtInfos);
    	this.setModuleName(prgInfo.getModuleName());
    }
    
    public PrgInfoDTO(PrgInfo prgInfo, List<PrgExtInfo> prgExtInfos, String runningStatus) {
    	this.setPrgId(prgInfo.getPrgId());
    	this.setPrgName(prgInfo.getPrgName());
    	this.setGroupName(prgInfo.getGroupName());
    	this.setDeployId(prgInfo.getDeployId());
    	this.setDeployDir(prgInfo.getDeployDir());
    	this.setConfDir(prgInfo.getConfDir());
    	this.setLogDir(prgInfo.getLogDir());
    	this.setLogBakDir(prgInfo.getLogBakDir());
    	this.setDesc(prgInfo.getDesc());
    	this.setStatus(prgInfo.getStatus());
    	this.setInsertTime(prgInfo.getInsertTime());
    	this.setInsertStaffId(prgInfo.getInsertStaffId());
    	this.setLastModTime(prgInfo.getLastModTime());
    	this.setLastModStaffId(prgInfo.getLastModStaffId());
    	this.setPrgExtInfos(prgExtInfos);
    	this.setRunningStatus(runningStatus);
    }
    
    public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

    public String getPrgId() {
        return prgId;
    }

    public void setPrgId(String prgId) {
        this.prgId = prgId == null ? null : prgId.trim();
    }

    public String getPrgName() {
        return prgName;
    }

    public void setPrgName(String prgName) {
        this.prgName = prgName == null ? null : prgName.trim();
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName == null ? null : groupName.trim();
    }

    public String getDeployId() {
        return deployId;
    }

    public void setDeployId(String deployId) {
        this.deployId = deployId == null ? null : deployId.trim();
    }

    public String getDeployDir() {
        return deployDir;
    }

    public void setDeployDir(String deployDir) {
        this.deployDir = deployDir == null ? null : deployDir.trim();
    }

    public String getConfDir() {
        return confDir;
    }

    public void setConfDir(String confDir) {
        this.confDir = confDir == null ? null : confDir.trim();
    }

    public String getLogDir() {
        return logDir;
    }

    public void setLogDir(String logDir) {
        this.logDir = logDir == null ? null : logDir.trim();
    }

    public String getLogBakDir() {
        return logBakDir;
    }

    public void setLogBakDir(String logBakDir) {
        this.logBakDir = logBakDir == null ? null : logBakDir.trim();
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc == null ? null : desc.trim();
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status == null ? null : status.trim();
    }

    public Date getInsertTime() {
        return insertTime;
    }

    public void setInsertTime(Date insertTime) {
        this.insertTime = insertTime;
    }

    public String getInsertStaffId() {
        return insertStaffId;
    }

    public void setInsertStaffId(String insertStaffId) {
        this.insertStaffId = insertStaffId == null ? null : insertStaffId.trim();
    }

    public Date getLastModTime() {
        return lastModTime;
    }

    public void setLastModTime(Date lastModTime) {
        this.lastModTime = lastModTime;
    }

    public String getLastModStaffId() {
        return lastModStaffId;
    }

    public void setLastModStaffId(String lastModStaffId) {
        this.lastModStaffId = lastModStaffId == null ? null : lastModStaffId.trim();
    }

	public List<PrgExtInfo> getPrgExtInfos() {
		return prgExtInfos;
	}

	public void setPrgExtInfos(List<PrgExtInfo> prgExtInfos) {
		this.prgExtInfos = prgExtInfos;
	}

	public String getRunningStatus() {
		return runningStatus;
	}

	public void setRunningStatus(String runningStatus) {
		this.runningStatus = runningStatus;
	}

	public String getRunningStatusStr() {
		if (null == this.runningStatus) {
			return "未知";
		}
		if (this.runningStatus.equals(RunningStatus.RUNNINGSTATUS_RUN.getCode())) {
			return "启动";
		}
		if (this.runningStatus.equals(RunningStatus.RUNNINGSTATUS_PAUSE.getCode())) {
			return "暂停";
		}
		if (this.runningStatus.equals(RunningStatus.RUNNINGSTATUS_STOP.getCode())) {
			return "停止";
		}
		return "未知";
	}

	public void setRunningStatusStr(String runningStatusStr) {
		this.runningStatusStr = runningStatusStr;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	public Long getRunHours() {
		return runHours;
	}

	public void setRunHours(Long runHours) {
		this.runHours = runHours;
	}
	
	public String getRunTime() {
		if (null == this.runHours) {
			return runTime;
		}
		if (this.runHours >= 60) {
			String time = "";
			Double minD = Math.floor(this.runHours / 60);
			int min = minD.intValue();
			Double secD = Math.floor(this.runHours % 60);
			int sec = secD.intValue();
			if (min < 60) {
				time += min + "分";
				if (sec > 0) time += sec + "秒";
				return time;
			}
			int hour = min / 60;
			min = min % 60;
			if (hour < 24) {
				time += hour + "时";
				if (min > 0) time += min + "分";
				if (sec > 0) time += sec + "秒";
				return time;
			}
			int day = hour / 24;
			hour = hour % 24;
			time += day + "天";
			if (hour > 0) time += hour + "时";
			if (min > 0) time += min + "分";
			if (sec > 0) time += sec + "秒";
			return time;
		}
		return runHours + "秒";
	}

	public void setRunTime(String runTime) {
		this.runTime = runTime;
	}
	
}
